from DataAccess.DBConnFactory import *

from string import Template

def query_stock_currency(ticker):

	sql_tpl = Template('''select Currency from SecurityCode where Symbol='${TICKER}' ''')												
	sql_text = sql_tpl.substitute(TICKER = ticker)
	
	cursor = DBConnFactory().get_db_connection('FINCHINA').cursor()
	cursor.execute(sql_text)
	r = cursor.fetchall()
	
	if r:
		return r[0][0]
	else:
		print '      err info...failed in querying stock currency,', ticker

def query_index_currency(ticker):

	sql_tpl = Template('''select Currency from IPROFILE where Symbol='${TICKER}' ''')												
	sql_text = sql_tpl.substitute(TICKER = ticker)
	
	cursor = DBConnFactory().get_db_connection('FINCHINA').cursor()
	cursor.execute(sql_text)
	r = cursor.fetchall()
	
	if r:
		return r[0][0]
	else:
		print '      err info...failed in querying index currency,', ticker

def query_futures_currency(ticker):

	return 'CNY' #to be implemented